<template>
	<view class="page" :style="'background-image: url('+indexBg+');'">
    <u-navbar :fixed="false" title="查看" placeholder bgColor="transparent"></u-navbar>
    <view class="detail-box u-m-t-48 u-m-b-32">
      <image class="detail-status" src="https://gowork365.com/prod-api/profile/mini/company/status1.png" />
      <view class="detail-name">{{ form.investorName }}</view>
      <view class="detail-tel">{{ form.contact }} {{ form.phoneNumber }}</view>
      <view class="detail-box-title">
        <image src="https://gowork365.com/prod-api/profile/mini/company/title2.png" mode="widthFix" />
        <text>简介</text>
      </view>
      <view class="detail-box-content u-m-b-28">
        {{ form.investorDesc || '-' }}
      </view>
    </view>
    <view class="contract-list">
      <view class="list-item" v-for="item in form.gwContracts" :key="item.id">
        <view class="list-title" v-if="item == 0">
          <image src="https://gowork365.com/prod-api/profile/mini/company/title3.png" mode="widthFix" />
          <text>签署的合同</text>
        </view>
        <view class="info">
          <image src="https://gowork365.com/prod-api/profile/mini/company/list2.png" />
          <view class="u-flex-1">
            <view class="title u-line-2">{{ item.contractName }}</view>
            <view class="time">{{ item.createTime }}</view>
          </view>
          <view class="status" style="color: #E69945;border-color: #E69945;">{{ item.statusName || item.status }}</view>
        </view>
        <view class="actions">
          <view class="actions-item" v-if="item.status !== 'All'&&item.izHistory == '否'" style="background: #FFDFE5;color: #FE748B;" @click="handleRevoke(item)">
            <image src="https://gowork365.com/prod-api/profile/mini/company/action1.png" />
            <text>撤销</text>
          </view>
          <view class="actions-item" style="background: #E9F8F6;color: #138E88;" @click="handleForm(item)">
            <image src="https://gowork365.com/prod-api/profile/mini/company/action3.png" />
            <text>查看</text>
          </view>
          <!-- <view class="actions-item" style="background: #E9F8F6;color: #138E88;" v-if="item.izHistory == '是'" @click="handleDown(item)">
            <image src="https://gowork365.com/prod-api/profile/mini/company/action2.png" />
            <text>下载PDF合同</text>
          </view> -->
        </view>
      </view>
    </view>
	</view>
</template>

<script>
import { contractRevoke, getInvestor, getSignUrl } from '@/api/index'
import { downloadFile } from '@/common/util'

export default {
  data() {
    return {
      indexBg: 'https://gowork365.com/prod-api/profile/mini/index/indexBg1.png',
      id: '',
      form: {},
    }
  },
  onLoad(options) {
    if(options.id) {
      this.id = options.id
      this.getForm()
    }
  },
  methods: {
    /** 撤销按钮操作 */
    handleRevoke(row) {
      const id = row.id;
      const that = this
      uni.showModal({
        title: '是否确认撤销此合同？',
        editable: true,
        placeholderText: '请输入撤销原因',
        success: async function (res) {
          if (res.confirm) {
            if(res.content == '') {
              uni.showToast({
                icon: 'none',
                title: '请输入撤销原因',
              })
            } else {
              uni.showLoading({ mask: true })
              await contractRevoke({id: id, cancelMessage: res.content})
              uni.hideLoading()
              that.getForm()
            }
          }
        }
      });
    },
    handleForm(row) {
      if(row.izHistory == '是') {
        const url = this.baseUrl + row.contractUrl
        downloadFile(url)
      } else {
        getSignUrl(row).then(response => {
          const previewUrl = response.data.url
          wx.navigateToMiniProgram({
            appId: this.baseAppId,
            path: previewUrl, // 跳转的页面路径，可选，默认跳转到目标小程序首页; 签署时，需使用后台API返回的完整链接（类似pages/guide?id=xxx&foo=bar）
            envVersion: 'release', // 跳转正式或demo小程序，都需要传 'release'
            success(res) {
            },
            fail(err) {
              // 跳转失败的回调函数
              console.log(err);
              uni.showToast({
                icon: 'none',
                title: '跳转三方小程序失败',
              })
            }
          })
        })
      }
    },
    handleDown(row) {
      if(row.izHistory == '是') {
        const url = this.baseUrl + row.contractUrl
        downloadFile(url)
      } else {
        getSignUrl(row).then(response => {
          const previewUrl = response.data.url
          wx.navigateToMiniProgram({
            appId: this.baseAppId,
            path: previewUrl, // 跳转的页面路径，可选，默认跳转到目标小程序首页; 签署时，需使用后台API返回的完整链接（类似pages/guide?id=xxx&foo=bar）
            envVersion: 'release', // 跳转正式或demo小程序，都需要传 'release'
            success(res) {
            },
            fail(err) {
              // 跳转失败的回调函数
              console.log(err);
              uni.showToast({
                icon: 'none',
                title: '跳转三方小程序失败',
              })
            }
          })
        })
      }
    },
    getForm() {
      uni.showLoading({ mask: true })
      getInvestor(this.id).then(response => {
        uni.hideLoading()
        this.form = response.data;
      });
    },
  }
}
</script>

<style lang="scss" scoped>
.page{
	width: 750rpx;
	min-height: 100vh;
  background: #F4F7F6;
  position: relative;
  background-repeat: no-repeat;
  background-size: 750rpx 348rpx;
  padding-bottom: 180rpx;
  .detail-box {
    width: 686rpx;
    margin: 0 auto;
    padding: 32rpx;
    background: #FFFFFF;
    box-shadow: 0rpx 8rpx 20rpx 0rpx rgba(11,102,97,0.2);
    border-radius: 16rpx;
    position: relative;
    .detail-status {
      position: absolute;
      top: 0;
      right: 0;
      width: 96rpx;
      height: 44rpx;
    }
    .detail-name {
      font-size: 28rpx;
      color: rgba(0,0,0,0.85);
      margin-bottom: 16rpx;
    }
    .detail-tel {
      font-size: 24rpx;
      color: rgba(0,0,0,0.25);
      margin-bottom: 32rpx;
    }
    .detail-box-title {
      display: flex;
      align-items: center;
      gap: 8rpx;
      margin-bottom: 28rpx;
      image {
        width: 32rpx;
        height: auto;
      }
      text {
        font-family: PingFang-SC, PingFang-SC;
        font-size: 24rpx;
        color: rgba(0,0,0,0.85);
      }
    }
    .detail-box-content {
      width: 100%;
      background: rgba(255,239,221,.5);
      border-radius: 16rpx;
      padding: 28rpx;
      line-height: 44rpx;
      font-size: 24rpx;
      font-family: PingFang-SC, PingFang-SC;
      .detail-box-item {
        font-family: PingFang-SC, PingFang-SC;
        margin-bottom: 16rpx;
        font-size: 24rpx;
        line-height: 34rpx;
      }
      .detail-box-item:last-child {
        margin-bottom: 0;
      }
    }
  }
  .contract-list {
    width: 686rpx;
    margin: 0 auto;
    .list-item {
      margin-bottom: 32rpx;
      width: 686rpx;
      background: #FFFFFF;
      box-shadow: 0rpx 8rpx 20rpx 0rpx rgba(11,102,97,0.2);
      border-radius: 16rpx;
      padding: 48rpx 32rpx 40rpx;
      .list-title {
        display: flex;
        align-items: center;
        gap: 8rpx;
        margin-bottom: 32rpx;
        image {
          width: 32rpx;
          height: auto;
        }
        text {
          font-family: PingFang-SC, PingFang-SC;
          font-size: 24rpx;
          color: rgba(0,0,0,0.85);
        }
      }
      .info {
        height: 138rpx;
        margin-bottom: 48rpx;
        display: flex;
        gap: 24rpx;
        image {
          width: 104rpx;
          height: 104rpx;
          flex-shrink: 0;
        }
        .title {
          font-size: 28rpx;
          color: rgba(0,0,0,0.85);
          margin-bottom: 16rpx;
        }
        .time {
          font-size: 24rpx;
          color: rgba(0,0,0,0.25);
        }
        .status {
          padding: 0 20rpx;
          height: 44rpx;
          line-height: 40rpx;
          border-radius: 200rpx;
          border: 2rpx solid;
          font-family: PingFangSC, PingFang SC;
          font-size: 24rpx;
          flex-shrink: 0;
        }
      }
      .actions {
        display: flex;
        gap: 24rpx;
        .actions-item {
          flex: 1;
          height: 76rpx;
          border-radius: 8rpx;
          display: flex;
          align-items: center;
          justify-content: center;
          gap: 4rpx;
          font-family: PingFangSC, PingFang SC;
          font-size: 24rpx;
          image {
            width: 32rpx;
            height: 32rpx;
          }
        }
      }
    }
  }
}
</style>
